package com.test.springboot3.springboot3testdemo1.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2024/8/6-下午3:44
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RequiredArgsConstructor
@RestController
@Slf4j
public class JmsMsgController {
  private final JmsTemplate jmsTemplate;

  @RequestMapping("/sendJms")
  public String sendMsg(@RequestParam("msg") String msg) {
    jmsTemplate.convertAndSend("test-queue", msg);
    return "success";
  }

  @JmsListener(destination = "test-queue")
  public void receiveMsg(String msg) {
    log.info("[JMS] receive msg: {}", msg);
  }
}
